import { fullGatesMetricData } from '../fullAmountCodeFailedConditionsDs';
import { newGatesMetricData } from '../newCodeFailedConditionsDs';
import { IConditionItem } from '../index';

interface IconditionList extends IConditionItem {
  gatesScope: 'all' | 'new'
  actualValue:string
}

const textMap = new Map([
  ['all', '全量'],
  ['new', '新'],
]);

export function transFormConditions(conditionList: IconditionList[]) {
  const totalAll = fullGatesMetricData.concat(newGatesMetricData);
  const returnArr: { success: boolean; text: string;actualValue:string;gatesMetric:string }[] = [];
  conditionList.forEach((item) => {
    const obj = {
      success: false,
      text: '',
      actualValue: '',
      gatesMetric: '',
    };
    const found = totalAll.find((i) => i.value === item.gatesMetric);
    if (found) {
      const isPercentage = ['new_duplicated_lines_density', 'duplicated_lines_density'].includes(item.gatesMetric);
      obj.success = +item.gatesValue > +item.actualValue;
      obj.text = `${found.meaning}高于${item.gatesValue}${isPercentage ? '%' : ''} (${textMap.get(item.gatesScope)}代码)`;
      obj.actualValue = isPercentage ? `${item.actualValue}%` : item.actualValue;
      obj.gatesMetric = item.gatesMetric;
      returnArr.push(obj);
    }
  });
  return returnArr;
}
